package com.xinxing.learning.statemachine.enums;

public enum OrderStatus {
    WAIT_PAYMENT(1, "待支付"),
    WAIT_DELIVER(2, "待发货"),
    WAIT_RECEIVE(3, "待收货"),
    FINISH(4, "已完成");
    private Integer key;
    private String desc;

    OrderStatus(int key, String desc) {
        this.key = key;
        this.desc = desc;
    }

    public Integer getKey() {
        return key;
    }

    public String getDesc() {
        return desc;
    }

    public static OrderStatus getByKey(Integer key) {
        for (OrderStatus orderStatus : values()) {
            if (orderStatus.getKey().equals(key)) {
                return orderStatus;
            }
        }
        throw new RuntimeException("enum not exists");
    }
}
